package com.mudalov.rec.dao.factory;

import com.mudalov.rec.dao.interfaces.IAdminDAO;
import java.util.HashMap;
import java.util.Map;

import com.mudalov.rec.dao.interfaces.IDbInitializer;
import com.mudalov.rec.dao.interfaces.IMaterialDAO;
import com.mudalov.rec.dao.interfaces.IQuestionDAO;
import com.mudalov.rec.dao.interfaces.IRoleDAO;
import com.mudalov.rec.dao.interfaces.IStudentDAO;
import com.mudalov.rec.dao.interfaces.IStudyProgramDAO;
import com.mudalov.rec.dao.interfaces.ISubjectDAO;
import com.mudalov.rec.dao.interfaces.ITeacherDAO;
import com.mudalov.rec.dao.interfaces.ITestDAO;
import com.mudalov.rec.dao.interfaces.ITestResultDAO;


public abstract class DAOFactory {
	
	public static final Class<? extends DAOFactory> HIBERNATE_MY_SQL = MySqlHbnDAOFactory.class;
	
	public static final Class<? extends DAOFactory> HIBERNATE_POSTGRE = PostgreHbnDAOFactory.class;

	private static Map<Class<? extends DAOFactory>, DAOFactory> factories = new HashMap<Class<? extends DAOFactory>, DAOFactory>();
	
	public static DAOFactory getFactory(Class<? extends DAOFactory> factoryClass) {
		DAOFactory factory = factories.get(factoryClass);
		if (factory == null) {
			try {
				factory = factoryClass.newInstance();
				factories.put(factoryClass, factory);
			} catch (Exception e) {
				e.printStackTrace();
				throw new IllegalArgumentException();
			}
		}
		return factory;
	}
	
	public abstract IMaterialDAO getMaterialDAO();
	
	public abstract IQuestionDAO getQuestionDAO();
	
	public abstract IStudyProgramDAO getStudyProgramDAO();
	
	public abstract ISubjectDAO getSubjectDAO();
	
	public abstract ITestDAO getTestDAO();
	
	public abstract ITestResultDAO getTestResultDAO();
	
	public abstract IDbInitializer getDbInitializer();

    public abstract IRoleDAO getRoleDAO();

    public abstract IStudentDAO getStudentDAO();

    public abstract IAdminDAO getAdminDAO();

    public abstract ITeacherDAO getTeacherDAO();
}
